import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("Provider")),
        body: ListView(
          children: [
            Center(
              child: Listener(
                child: Container(
                  width: 200,
                  height: 200,
                  color: Colors.red,
                  child: Center(
                      child: Text("Listener", style: TextStyle(color: Colors.white, fontSize: 20))),
                ),
                onPointerDown: (e) {
                  print("指针按下 在整个屏幕的位置： ${e.position} 在容器中的位置：${e.localPosition}");
                },
                onPointerUp: (e) {
                  print("指针抬起");
                },
                onPointerMove: (e) {
                  print("指针移动");
                },
              ),
            ),
            SizedBox(height: 50),
            Center(
              child: GestureDetector(
                child: Container(
                  width: 200,
                  height: 200,
                  color: Colors.blue,
                  child: Center(
                      child: Text("Gesture", style: TextStyle(color: Colors.white, fontSize: 20))),
                ),
                onTap: () {
                  print("手势点击");
                },
                onTapDown: (details) {
                  print("手势按下 全屏位置： ${details.globalPosition}，容器位置 ${details.localPosition}");
                },
                onTapUp: (details) {
                  print("手势抬起");
                },
                onTapCancel: () {
                  print("手势取消");
                },
                onDoubleTap: () {
                  print("手势双击");
                },
                onLongPress: () {
                  print("长按手势");
                },
              ),
            ),
            SizedBox(height: 50),
            Center(
              child: GestureDetector(
                child: Container(
                  width: 200,
                  height: 200,
                  color: Colors.yellow,
                  child: Center(
                    child: GestureDetector(
                      child: Container(
                        width: 100,
                        height: 100,
                        color: Colors.black,
                      ),
                      onTap: () => print("黑色块被点击"),
                    ),
                  ),
                ),
                onTap: () {
                  print("黄色块被点击");
                },
              ),
            ),
            SizedBox(height: 50),
            Center(
              child: Stack(
                alignment: Alignment.center,
                children: [
                  GestureDetector(
                    child: Container(
                      width: 200,
                      height: 200,
                      color: Colors.yellow,
                    ),
                    onTap: () {
                      print("黄色块被点击");
                    },
                  ),
                  GestureDetector(
                    child: Container(
                      width: 100,
                      height: 100,
                      color: Colors.black,
                    ),
                    onTap: () => print("黑色块被点击"),
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
